package com.hmall.cart.listener;


import com.hmall.cart.service.ICartService;
import com.hmall.common.constants.MqConstants;
import com.hmall.common.domain.dto.CartItemDeleteDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class OrderDeleteCartListener {

    private final ICartService cartService;

    // 监听支付成功消息, 更新订单状态
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstants.CART_CLEAR_QUEUE, durable = "true"),
            exchange = @Exchange(name = MqConstants.TRADE_EXCHANGE_NAME, type = "direct"),
            key = MqConstants.ORDER_CREATE_KEY
    ))
    public void listenPaySuccess(CartItemDeleteDTO cartItemDeleteDTO) {
        cartService.removeByItemIds(cartItemDeleteDTO);
    }
}
